# Modified for the MIP - Mike Schladt - 2014

# Copyright (C) 2010-2014 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

import os
import json

from lib.cuckoo.common.abstracts import Report
from lib.cuckoo.common.exceptions import CuckooReportError

class MipJsonDump(Report):

    def run(self, results):
        """Writes report.
        @param results: Cuckoo results dict.
        @raise CuckooReportError: if fails to write report.
        """
        json_arch_dir= 'YOUR_DIR_HERE' # EDIT THIS LINE

        try:
            file_name = results['target']['file']['md5']+".json"
            path = os.path.join(json_arch_dir, file_name)
            report = open(path, "w")
            json.dump(results, report)
            report.close()
        except (UnicodeError, TypeError, IOError) as e:
            raise CuckooReportError("Failed to generate MIP JSON report: %s" % e)
